﻿<extend name="Public:base" />
<block name="title"><title>用户登陆</title></block>
<block name="header_styles">
    <style type="text/css">
        .login-section {
            margin: auto;
            width: 400px;
            padding-top: 50px;
        }
    </style>
</block>
<block name="main">
    <div class="login-section">
        <div class="panel panel-green">
            <div class="panel-heading">用户登陆</div>
            <div class="panel-body">
                <p id="signintip" style="color: #f00;display: none;"></p>
                <form id="formLogin">
                    <div class="form-group">
                        <input type="text" name="email" id="email" data-val="true" data-val-required="用户名不能为空" placeholder="请输入您的登陆邮箱" class="form-control" />
                        <span data-valmsg-for="email" data-valmsg-replace="true"></span>
                    </div>
                    <div class="form-group">
                        <input type="password" name="password" id="pwd" placeholder="请输入您的密码" data-val="true" data-val-required="密码不能为空" class="form-control" />
                        <span data-valmsg-for="password" data-valmsg-replace="true"></span>
                    </div>
                    <div class="row">
                        <div class="col-xs-7">
                            <div>
                                <label class="checkbox-inline">
                                    <input id="remember" type="checkbox" value="1" /> 一周内不用登陆
                                </label>
                                &nbsp;
                                &nbsp;
                                <a href="{:U('Login/resetpwd', array('step'=>1))}" class="link-style1" id="link_forgot" style="vertical-align: middle;">忘记密码?</a>
                            </div>
                        </div>
                        <div class="col-xs-5 text-right">
                            <button type="submit" id="submitbtn" class="btn btn-success">登陆</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</block>
<block name="footer_scripts">
    <if condition="$signuped eq 1">
    <script type="text/javascript">
        require(["jquery", "modules/message"], function ($, message) {
            message.alert({ content: '该账户已注册，可登陆！' });
        });
    </script>
    </if>
    <script type="text/javascript">
        require(["jquery"],function($){
            $(document).ready(function () {
                $('#formLogin').on("submit",function () {
                    if (!$("#formLogin").valid()) {
                        return false;
                    }
                    gologin();
                    return false;
                });
            });
            //登陆提交
            function gologin() {
                $('#signintip').hide();
                var url = "{:U('Login/login_ajax', '', '')}";
                var email = $('#email').val();
                var pwd = $('#pwd').val();
                var remember = 0;
                if($("#remember").is(':checked')){
                    remember = 1;
                };
                var isRedirect = 1;//登陆后是否跳转

                $.ajax({
                    type: "get",
                    //data:{ 'email': email, 'userpwd': userpwd, 'rem': remember },
                    async: false,
                    url: url+'-email-'+email+'-userpwd-'+pwd+'-remember-'+remember+'-redirect-1',
                    dataType: "jsonp",
                    jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
                    jsonpCallback:"callme",//自定义的jsonp回调函数名称，默认为jQuery自动生成的随机函数名，也可以写"?"，jQuery会自动为你处理数据
                    success: function(data){
                        if (data.success == 1) {
                            if(data.url){
                                window.location.href = data.url;
                            }
                        }
                        else {
                            $('#signintip').text(data.msg);
                            $('#signintip').show();
                        }
                    },
                    error: function(){
                        $('#signintip').text(data.msg);
                        $('#signintip').show();
                    }
                });
                return false;
            };
        });
    </script>
</block>
